package address

import (
	"gitee.com/xgotool/backend-framework-template/model"
	"gitee.com/xgotool/backend-framework-template/service/address"
	"gitee.com/xgotool/backend-framework-template/service/users"
	"gitee.com/xiaoyutab/xgotool/individual/xginplus"
)

// 创建/修改地址接口
//
//	POST	admin/user/address/create
func AdminCreate(c *xginplus.Context) *xginplus.Response {
	type param struct {
		UserName string        `json:"user_name"` // 用户名
		Address  model.Address `json:"address"`
	}
	mod := param{}
	err := c.RBind(&mod)
	if err != nil {
		return c.Error(err)
	}
	if mod.Address.Uid == 0 {
		mod.Address.Uid, err = users.GetId(mod.UserName)
		if err != nil {
			return c.Error(err)
		}
	}
	err = address.Create(&mod.Address)
	if err != nil {
		return c.Error(err)
	}
	return c.SuccessEmpty()
}
